package com.example.controller;

import com.example.common.Result;
import com.example.entity.farm.dto.StockPlayerFarmDTO;
import com.example.mapper.dao.FarmDao;
import com.example.service.FarmService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/ziziFarm")
public class FarmController {

    @Autowired
    private FarmService farmService;

    @Resource
    private FarmDao farmDao;

    @GetMapping("/isFarm")
    public Result isFarm(String uid)
    {
        if(farmDao.selectIsFarm(uid)!=0)
        {
            return Result.success("YesFarm");
        }
        return Result.success("NotFarm");
    }

    @PostMapping("/goFarm")
    public Result goFarm(String uid,String itemId)
    {
        return Result.success(farmService.goFarm(uid, itemId));
    }

    @PutMapping("/plant")
    public Result plant(String uid, Integer fertilizer)
    {
        System.out.println(uid+fertilizer);
        return Result.success(farmService.plant(uid, fertilizer));
    }

    @GetMapping("/desc")
    public Result desc(String uid)
    {
        StockPlayerFarmDTO stockPlayerFarmDTO = farmService.desc(uid);
        return Result.success(stockPlayerFarmDTO);
    }

    @GetMapping("/task")
    public Result task(String uid){
        return Result.success(farmDao.task(uid));
    }

}
